<?php

namespace App\Excels\Exports;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithDrawings;
use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Concerns\WithTitle;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;

class ProjectMallExport implements FromCollection,WithStyles, WithDrawings,WithTitle
{
    protected mixed $data;
    protected mixed $ifMy;

    public function __construct($data,$ifMy){
        $this->data = $data;
        $this->ifMy = $ifMy;
    }

    public function collection(): Collection
    {
        //
        $xlsData = [
            [
                "项目名称",
                "回款金额",
                "回款比例",
                "收益金额",
                "出资金额",
                "收益比例",
                "应收总额",
                "状态",
            ]
        ];
        foreach($this->data as $data){
            $incomStatus = "";
            switch ((int)$data->incom_status){
                case 0:
                    $incomStatus = "回本期";
                    break;
                case 1:
                    $incomStatus = "收益期";
                    break;
                case 2:
                    $incomStatus = "已结束";
                    break;
            }
            $tmp = [
                (string)$data->mall->name,
                (string)($this->ifMy ? $data->my_back_money : $data->back_money),
                ((string)round($data->back_rate,2))."%",
                (string)($this->ifMy ? $data->my_incom_money : $data->incom_money),
                (string)($this->ifMy ? $data->my_money : $data->money),
                ((string) $data->income_rate)."%",
                (string)($this->ifMy ? $data->my_all_money : $data->all_money),
                $incomStatus,

            ];
            $xlsData[] = $tmp;
        }

        return collect($xlsData);
    }
    public function styles(Worksheet $sheet){

    }
    public function drawings(){
        return [];
    }
    public function title(): string
    {
        return "工作表1";
    }
}
